package api

import (
	"weiboxs.com/new_h_glasses/enums"
	"weiboxs.com/new_h_glasses/models"
)

type ApiInventoryController struct {
	ApiBaseController
}

//查看库存
func (c *ApiInventoryController) ApiInventory() {
	c.checkAuthor("inventory/inventory")

	c.getInventoryProduct()

	config := make(map[string]interface{})
	//获取类别
	config["class"] = models.ErpClassTree()
	//获取品牌
	config["brand"] = models.ErpBrandList(&models.ErpBrandQueryParam{DepartmentId:c.curUser.DepartmentId})
	//供应商
	config["suppliers"] = models.ErpSuppliersList(&models.ErpSuppliersQueryParam{DepartmentId:c.curUser.DepartmentId})
	//输出屈光度
	config["diopters"] = c.showDiopterRange()

	c.jsonResult(enums.JRCodeSucc, "ok", config)
}

//输出屈光度
func(c *ApiInventoryController) showDiopterRange() []string {
	return nil
}
//获取库存产品
func (c *ApiInventoryController) getInventoryProduct() {

	if c.Ctx.Input.IsPost() { //POST提交返回数据

		var params models.ErpInventoryQueryParam

		limit,_ := c.GetInt("limit", 20)
		offset,_ := c.GetInt64("offset", 0)
		filter := c.GetString("keyword")
		query_dr := c.GetString("query_dr")
		query_am := c.GetString("query_am")

		params.Limit = limit
		params.Offset = offset
		params.Filter = filter
		params.QueryDr = query_dr
		params.QueryAm = query_am

		dep,_ :=  c.GetInt64("from_dep_id")
		params.Department = dep

		data, total := models.ErpInventoryPageList(&params)

		c.jsonResultData(enums.JRCodeSucc, total, data)
	}
}